//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreateJobPosition {
        private readonly IJobPositionRepository _jobPositionRepository;

        public CreateJobPosition(IJobPositionRepository jobPositionRepository) {
            _jobPositionRepository = jobPositionRepository;
        }

        public void Execute(Guid userId, ICreateJobPositionCommand jobPositionForm) {
            if (jobPositionForm == null)
                throw new ArgumentNullException("jobPositionForm");

            try {
                var jobPosition = jobPositionForm.ConvertToEntity();
                _jobPositionRepository.Create(jobPosition);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
